/**
 * @file       godemool/playerinfo.h
 * @brief      player info class.
 * @author     ben "boin" bonoeil
 * @date       2015-02
 */

/* Copyright (c) 2007-2015, ben "boin" bonoeil */

#ifndef GODEMOOL_PLAYERINFO_H
#define GODEMOOL_PLAYERINFO_H

#include "godemool/csgo.h"
#include "godemool/types.h"
#include <vector>

namespace boin {
  struct PlayerInfo;
  struct PlayerList;
}

struct boin::PlayerInfo
{
  enum {
    CUSTOM_FILES = 4,
    NAME_LEN     = 128,
    GUID_LEN     = 32+1,
    INVALID_UID  = -1,
    INVALID_FID  = -1,
  };

  PlayerInfo();
  void Clear();

  bool operator == ( uint64_t p_xid ) const { return xid == p_xid; }
  bool operator == ( uint32_t p_uid ) const { return uid == p_uid; }

  uint64_t version; // version for future compatibility
  uint64_t xid;     // network xuid
  uint32_t uid;     // local server user ID, unique while server is running
  uint32_t fid;     // friends identification number
  std::string guid; // global unique player identifer
  std::string name; // scoreboard information
  std::string friendsName; // friends name
  bool isFake; // true, if player is a bot controlled by game.dll
  bool isHltv; // true if player is the HLTV proxy
  std::vector<uint32_t> customFilesCrc; // custom files CRC for this player
  uint16_t dlFilesCount; // Incremented on server download
};

struct boin::PlayerList : public std::vector<boin::PlayerInfo>
{
  template <typename T> PlayerInfo * Find(T something) {
    for (auto it = begin(); it != end(); ++it)
      if ((*it) == something)
        return &(*it);
    return nullptr;
  }
  PlayerInfo * Find(uint32_t uid); ///< Looking  for UID
  PlayerInfo * Find(uint64_t xid); ///< Looking for eXtended UID
  PlayerInfo & Update(const PlayerInfo & pi);
};

#endif
